<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>地图选点</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="robots" content="all,follow">
    <!-- Bootstrap CSS-->
    <link rel="stylesheet" href="vendor/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome CSS-->
    <link rel="stylesheet" href="vendor/font-awesome/css/font-awesome.min.css">
    <!-- Fontastic Custom icon font-->
    <link rel="stylesheet" href="css/fontastic.css">
  
    <!-- theme stylesheet-->
    <link rel="stylesheet" href="css/style.default.css" id="theme-stylesheet">
    <!-- Custom stylesheet - for your changes-->
    <link rel="stylesheet" href="css/custom.css">
    <!-- Favicon-->
    <link rel="shortcut icon" href="img/favicon.ico">

  </head>
  <body>
    <div class="page">
     
        
      <div class="page-content d-flex align-items-stretch"> 
        <!-- Side Navbar -->
       
        <div class="content-inner" style="width: 100%;">
          <!-- Page Header-->
         
          <!-- Forms Section-->
          <section class="forms no-padding-top"> 
            <div class="container-fluid">
              <div class="row">
              
                <!-- Form Elements -->
                <div class="col-lg-12" >
                  <div class="card" >
                    <div class="card-close">
                      <div class="dropdown">
                        <button type="button" id="closeCard5" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="dropdown-toggle"><i class="fa fa-ellipsis-v"></i></button>
                        <div aria-labelledby="closeCard5" class="dropdown-menu dropdown-menu-right has-shadow"><a href="#" class="dropdown-item remove"> <i class="fa fa-times"></i>Close</a><a href="#" class="dropdown-item edit"> <i class="fa fa-gear"></i>Edit</a></div>
                      </div>
                    </div>
                    <div class="card-header d-flex align-items-center">
                      <h3 class="h4">地图选点（双击地图开始搜索）</h3>
                    </div>
                    <div class="card-body">
                      <form class="form-horizontal">
                        <div class="form-group row no-padding-bottom">
                          <label class="col-sm-3 form-control-label">具体地址</label>
                          <div class="col-sm-7">
                            <input type="text"  id="address" class="form-control" ></input>
                          </div>
                         <div class="col-sm-3"><label id="searchAddr"  class="btn btn-primary" >搜索</label></div>

                        </div>
                        <div class="form-group row no-padding-bottom">
                          <label class="col-sm-3 form-control-label">切换城市</label>
                          <div class="col-sm-5">
                            <input type="text"  id="city" class="form-control"></input>
                          </div>
                          <div class="col-sm-3"><label id="changecity"  class="btn btn-primary" >切换</label></div>
                        </div>
                       <div id="allmap" style="width: 100%;height: 600px;overflow: hidden;margin:0;font-family:"微软雅黑";"></div>
                      </form>
                    </div>
                    
                  </div>
                </div>
              </div>
            </div>
          </section>
         
        </div>
      </div>
    </div>
    <!-- JavaScript files-->
    <script src="vendor/jquery/jquery.min.js"></script>
    <script src="vendor/popper.js/umd/popper.min.js"> </script>
    <script src="vendor/bootstrap/js/bootstrap.min.js"></script>
    <script src="vendor/jquery.cookie/jquery.cookie.js"> </script>
    <script type="text/javascript" src="http://api.map.baidu.com/getscript?v=2.0&ak=ZRuPlmnlznoOhQsOvzAPU2ed85qbM2CW"></script>
    <!-- Main File-->
    <script src="js/front.js"></script>
    <script type="text/javascript" src="js/getUrlParam.js" ></script>
    <script type="text/javascript">
    	//获取url中的参数  需引入 getUrlParam.js
    		var address=UrlParm.parm("address"); 
    		$("#address").val(address);
    		$("city").val("银川");
    		$("#changecity").bind('click',function(){changeCity();});
    		$("#searchAddr").bind('click',function(){searchLocal();});
    		//初始搜索距离
				var range = 500;
    		var maxRange = 5000;//默认搜索最大半径
    		var rangeupper = 500;//距离增加梯度
    		// 百度地图API功能
				var map = new BMap.Map("allmap");    // 创建Map实例
				var point = new Object();
				map.centerAndZoom("银川", 12);  // 初始化地图,设置中心点坐标和地图级别
				//搜索结果
				var resultBox = new Object();
				
				//搜索结果数量
    		var resultNums = 0;
				//搜索参数
				var options = {
												renderOptions: {
													map: map
												},
				onSearchComplete: function(results) {
																//回调统计结果数量
																resultBox = results;
																//更新查询结果数量
																resultNums = results.getNumPois();
																console.log("range:"+range+"result:"+resultNums);
																if(range>=5000&&resultNums <3){
																	alert("案例不足，无法进行 案例比较法 估值，请联系案例维护员！")
																}
																
																if(range >=maxRange&&resultNums>3){
																	doJudge();
																}
																
															}
										};
				
				var localSearch = new BMap.LocalSearch(map, options);
				
				//添加地图类型控件

				map.addControl(new BMap.MapTypeControl({
					mapTypes:[
			            BMAP_NORMAL_MAP,
			            BMAP_HYBRID_MAP
			        ]}));	  

				map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
    		
    		map.addEventListener('dblclick',function(e){
    			point = e.point;
    			range=500;
    			resultNums=0;
    			searchCircle();
    		});
    		 
    		 
				
				
				/*
				 
				 * 以下为自定义函数功能区
				 * */
				
				
				
				//动态搜索圈内案例
				function searchCircle(){
					range = range + rangeupper;
					if(range>=maxRange&&resultNums==0){
						alert("当前范围内无案例，请联系案例管理员！");
						return 0;
					}
					//3000米范围内扫描出30个案例就足够了
					if(range<3000&&resultNums>=30){
						doJudge();
						return 0 ;
					}
					//若在5000米范围内搜索出来3个案例则成功
					if(range==5000&&resultNums<3){
						if(confirm("案例不足，可能会导致评级结果不准确，是否继续？")){
							doJudge();
						}else{
							return 0;
						}
						
					}
					if(range>maxRange){
						return 0;
					}
					if(range < maxRange){
						window.setTimeout("searchCircle("+range+")",1000);
					}
					
					map.clearOverlays();//清空覆盖物
					//绘制新圈
					var newcircle = new BMap.Circle(point,range,{fillColor:"blue", strokeWeight: 1 ,fillOpacity: 0.3, strokeOpacity: 0.3});
					if(range<2000){
						map.setZoom(15);
					}
					if(range>2500&&range<5000){
						map.setZoom(14);
					}

					map.addOverlay(newcircle);
					localSearch.searchNearby("case", point, range, {
								customData: {
									geotableId: 200599
								}
							});
							
				}
				
				
				
				
				
				
				
				
				
				
				function searchLocal(){
					var local = new BMap.LocalSearch(map, {
					renderOptions:{map: map}
								});
				local.search($("#address").val());
				}
				
				if($("#address").val()!=""){
					searchLocal();
				}
				
				function changeCity(){
					if($("#city").val()!=""){
						map.centerAndZoom($("#city").val(), 12);
					}
				}
				
				function doJudge(){
					alert("匹配成功！");
				}
    	
    </script>
  </body>
</html>
